//Copyright 2009 Dominik Punz
//
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
//http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.

#ifndef dispTestObjectList_h__
#define dispTestObjectList_h__

#include "dispTestObject.h"
#include "jniEnvironment.h"
#include <string>
#include <vector>

class CDispTestObjectList : public CDispatchImpl
{
public:
  CDispTestObjectList(CDesktop* desktop, jobject jobjListOfTestObject) : mDesktop(desktop), mjobjElements(jobjListOfTestObject), mJavaReflection(desktop)
  {
    CJniEnvironment jni;
    jni.Env()->NewGlobalRef(mjobjElements);
    InitializeList();
  }

  virtual ~CDispTestObjectList()
  {
    CJniEnvironment jni;
    jni.Env()->DeleteGlobalRef(mjobjElements);
  }

private:
  CDispTestObjectList() : mJavaReflection(0) { assert(false); }

protected:
  virtual BSTR ToString();
  virtual HRESULT InvokeDynamicMethod(const std::wstring& strDispName, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr);
  virtual HRESULT GetDynamicProperty(const std::wstring& strDispName, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr);
  virtual HRESULT SetDynamicProperty(const std::wstring& strDispName, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr);


public:
  void Add(const CComVariant& varValue)
  {
    mElements.push_back(varValue);
  }

private:
  void InitializeList();

private:
  CJavaReflection mJavaReflection;
  CComPtr<CDesktop> mDesktop;
  jobject mjobjElements;
  std::vector<CComVariant> mElements;
};

#endif // dispTestObjectList_h__